package com.wanpinghui.wphlibrary.model.db.manager;

import com.wanpinghui.wphlibrary.model.db.bean.MessageReadBean;
import com.wanpinghui.wphlibrary.model.db.bean.ObjectReadBean;
import com.wanpinghui.wphlibrary.model.object.bean.ObjectDetailBean;
import com.yunshl.yunshllibrary.storage.MDBManager;

import org.xutils.ex.DbException;

/***
 * 功能描述:
 * 作者:qiujialiu
 * 时间:2017/12/1
 ***/

public class ObjectDbManager {
    public static ObjectDbManager newInstance() {
        return new ObjectDbManager();
    }

    public void saveObjectRead(ObjectReadBean objectReadBean) {
        try {
            MDBManager.getInstance().getDbManager().saveOrUpdate(objectReadBean);
        } catch (DbException e) {
            e.printStackTrace();
        }
    }

    public void saveMessageRead(MessageReadBean messageReadBean) {
        try {
            MDBManager.getInstance().getDbManager().saveOrUpdate(messageReadBean);
        } catch (DbException e) {
            e.printStackTrace();
        }
    }

    public boolean isObjectRead(long id) {
        try {
            ObjectReadBean bean = MDBManager.getInstance().getDbManager().findById(ObjectReadBean.class,id);
            if (bean != null) {
                return bean.getIsRead() == 1;
            }
        } catch (DbException e) {
            e.printStackTrace();
        }
        return false;
    }

    public boolean isMessageRead(String id) {
        try {
            MessageReadBean bean = MDBManager.getInstance().getDbManager().findById(MessageReadBean.class,id);
            if (bean != null) {
                return bean.getIsRead() == 1;
            }
        } catch (DbException e) {
            e.printStackTrace();
        }
        return false;
    }
}
